package com.qfedu.dao.impl;

import com.qfedu.dao.BrandDao;
import com.qfedu.entity.Brand;
import com.qfedu.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2023/10/9 17:51
 */
public class BrandDaoImpl implements BrandDao {
    @Override
    public List<Brand> selectAll() {
        List<Brand> list=new ArrayList<>();
        String sql="select * from tb_brand";
        Connection conn= DBUtil.getConn();

        try {
            PreparedStatement pstm = conn.prepareStatement(sql);
            ResultSet resultSet = pstm.executeQuery();
            while (resultSet.next()){
                int id = resultSet.getInt("brand_id");
                String name = resultSet.getString("brand_name");
                String desc = resultSet.getString("brand_desc");
                Brand brand = new Brand();
                brand.setBrandId(id);
                brand.setBrandName(name);
                brand.setBrandDesc(desc);
                list.add(brand);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        return list;
    }
}
